package com._520it.crm.web.controller;

import com._520it.crm.domain.InformalStudent;
import com._520it.crm.page.AjaxResult;
import com._520it.crm.page.PageResult;
import com._520it.crm.query.InformalStudentQueryObject;
import com._520it.crm.service.IInformalStudentService;
import com._520it.crm.util.PermissionName;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/*/informalStudent---->访问informalStudent页面
/informalStudent/list---->informalStudent相关的数据
/informalStudent/save--->保存对象*/
@Controller
@RequestMapping("/informalStudent")
public class InformalController {
    @Autowired
    private IInformalStudentService informalStudentService;

    @RequiresPermissions("informalStudent:index")
    @PermissionName("潜在客户列表")
    @RequestMapping("")
    public String index() {
        System.out.println("in......." + informalStudentService);
        return "informalStudent";
    }

    @RequiresPermissions("informalStudent:list")
    @PermissionName("潜在客户数据")
    @RequestMapping("/list")
    @ResponseBody
    public PageResult list(InformalStudentQueryObject qo) {
        PageResult result = informalStudentService.queryPage(qo);
        return result;
    }

    @RequiresPermissions("informalStudent:save")
    @RequestMapping("/save")
    @ResponseBody
    @PermissionName("潜在客户新增")
    public AjaxResult save(InformalStudent informalStudent) {
        AjaxResult result = null;
        try {
            informalStudentService.insert(informalStudent);
            result = new AjaxResult(true, "保存成功");
        } catch (Exception e) {
            e.printStackTrace();
            result = new AjaxResult("保存失败,请联系管理员!");
        }
        return result;
    }

    @RequiresPermissions("informalStudent:update")
    @PermissionName("潜在客户更新")
    @RequestMapping("/update")
    @ResponseBody
    public AjaxResult update(InformalStudent informalStudent) {
        AjaxResult result = null;
        try {
            informalStudentService.updateByPrimaryKey(informalStudent);
            result = new AjaxResult(true, "更新成功");
        } catch (Exception e) {
            e.printStackTrace();
            result = new AjaxResult("更新失败,请联系管理员!");
        }
        return result;
    }

    @RequiresPermissions("informalStudent:quit")
    @PermissionName("潜在客户离职")
    @RequestMapping("/quit")
    @ResponseBody
    public AjaxResult quit(Long id) {
        AjaxResult result = null;
        try {
            informalStudentService.quit(id);
            result = new AjaxResult(true, "离职成功");
        } catch (Exception e) {
            e.printStackTrace();
            result = new AjaxResult("离职失败,请联系管理员!");
        }
        return result;
    }
}
